<template>
    <div class="select-cart">
        <no-data
                v-if="!cartMoudleMsg || ((!cartMoudleMsg.cartStoreInfos || cartMoudleMsg.cartStoreInfos.length == 0)  && (!cartMoudleMsg.invalidStoreInfos || cartMoudleMsg.invalidStoreInfos.length == 0))"
                :noDataProps="{text:'你购物车中还没有商品哦'}"></no-data>
        <div v-else-if="cartMoudleMsg && (Array.isArray(cartMoudleMsg.cartStoreInfos) && cartMoudleMsg.cartStoreInfos.length > 0) || (Array.isArray(cartMoudleMsg.invalidStoreInfos) && cartMoudleMsg.invalidStoreInfos.length > 0)">
            <ul class="sub-store-list positionR" v-for="(cartMoudleItem,cartMoudleKey) in cartMoudleMsg">
                <!--有效订单-->
                <li v-if="cartMoudleKey =='cartStoreInfos' && cartMoudleItem && cartMoudleItem.length > 0">
                    <ul class="sub-goods-list" v-for="(cartStoreInfo,cartStoreIndex) in cartMoudleItem">
                        <li class="displayFlex sub-store-msg">
                            <div v-if="!cartMoudleMsg.noSelectBtn" class="displayFlex flex-algin-center select-wImg">
                                <span v-if="cartMoudleKey == 'invalidStoreInfos'" class="disabled-select"></span>
                                <img class="select-img"
                                     @click="selectStore(cartStoreInfo.storeId,cartStoreInfo.selectAll)"
                                     v-else-if="cartStoreInfo.selectAll"
                                     src="../../../assets/images/cart/cart_select.png" alt="">
                                <img class="select-img"
                                     @click="selectStore(cartStoreInfo.storeId,cartStoreInfo.selectAll)"
                                     v-else src="../../../assets/images/cart/cart_not_select.png" alt="">
                            </div>
                            <div class="flex1 displayFlex flex-algin-center justifyCtBwt">
                            <span class="displayFlex flex-algin-center ">
                                <span class="cart-userheader-wimg">
                                    <img class="cart-userheader-img positionAbCenter" :src="cartStoreInfo.storeLogo"
                                         alt="">
                                </span>
                                <span class="cart-user-name">{{cartStoreInfo.storeName}}</span>
                            </span>
                                <span v-if="cartMoudleKey == 'cartStoreInfos'">
                                <span v-if="cartStoreInfo.upportExpress" class="cart-send-way">支持快递与自提</span>
                                <span v-else class="cart-send-way">仅支持自提</span>
                            </span>
                            </div>
                        </li>
                        <!--商品-->
                        <li v-if="cartStoreInfo && cartStoreInfo.cartItemInfos && cartStoreInfo.cartItemInfos.length > 0">
                            <div class="displayFlex cart-item" v-for="cartItemInfo in cartStoreInfo.cartItemInfos">
                                <cell-swipe
                                        :right="[
                                    {
                                      content: '删除',
                                      style: { background: 'red', color: '#fff' ,width: '.6rem',},
                                      handler: ()=>deleteItem(cartStoreInfo.storeId,cartItemInfo.id,cartMoudleKey)
                                    }
                                  ]">
                                    <div class="cart-citem displayFlex">
                                        <div v-if="!cartMoudleMsg.noSelectBtn"
                                             class="displayFlex flex-algin-center select-wImg">
                                            <span v-if="cartMoudleKey === 'invalidStoreInfos'"
                                                  class="disabled-select"></span>
                                            <img class="select-img"
                                                 @click="selectItem(cartStoreInfo.storeId,cartItemInfo.itemId,cartItemInfo.selected)"
                                                 v-else-if="cartItemInfo.selected"
                                                 src="../../../assets/images/cart/cart_select.png"
                                                 alt="">
                                            <img class="select-img"
                                                 @click="selectItem(cartStoreInfo.storeId,cartItemInfo.itemId,cartItemInfo.selected)"
                                                 v-else src="../../../assets/images/cart/cart_not_select.png" alt="">
                                        </div>
                                        <div class="cart-goods-wImg">
                                            <img v-if="Array.isArray(cartItemInfo.images) || cartItemInfo.itemImg"
                                                 class="cart-goods-img"
                                                 :src="cartItemInfo.images ? cartItemInfo.images[0] : cartItemInfo.itemImg"
                                                 alt="">
                                        </div>
                                        <div class="flex1 displayFlex goods-msg flex-wrap">
                                            <div class="width-full">
                                                <h6 class="width-full two-line-ellepsis item-title">
                                                    {{cartItemInfo.itemTitle}}</h6>
                                                <span class="cart-goods-style" v-if="cartItemInfo.styleName">
                                                    {{cartItemInfo.styleName}}
                                                </span>
                                                <!--这么暂时没有字段判断-->
                                                <span v-if="false"
                                                      class="warn-text displayBlock">此商品为定制商品，暂不支持退款！</span>
                                        </div>
                                        <div class="cart-goods-num displayFlex flex-algin-center width-full">
                                            <span class="flex1 fontSize12"><span class="font-size10">￥</span>{{Math.ceil(cartItemInfo.price * 100) / 100}}</span>
                                            <countor
                                                    v-if="cartItemInfo.maxBuyNum > 0"
                                                    :countNumProp="cartItemInfo.buyNum"
                                                    :countProp="getCountMsg(cartItemInfo,cartStoreInfo.storeId)"
                                                    @changeInputNumber="changeInputNumber"></countor>
                                        </div>
                                        </div>
                                    </div>
                                </cell-swipe>
                            </div>
                        </li>
                        <!--优惠信息-->
                        <li v-if="cartMoudleMsg.needDiscount">
                            <ul class="coupons-list">
                                <li class="coupons-item" v-if="cartStoreInfo.defaultUseTicket">
                                    <div class="coupons-citem" @click="$emit('selectedDiscount',cartStoreInfo.storeId)">
                                        <!--代金券-->
                                        <div class="displayFlex width-full justifyCtBwt"
                                             v-if="cartStoreInfo.defaultUseTicket.ticketType == 1 ">
                                            <div class="coupons-title">优惠券</div>
                                            <div class="coupons-title">
                                                <span v-if="cartStoreInfo.defaultUseTicket.ticketContent.cashPrice">-￥{{cartStoreInfo.defaultUseTicket.ticketContent.cashPrice}}元</span>
                                                <span class="iconfont icon-arrows_left"></span>
                                            </div>
                                        </div>
                                        <div class="displayFlex width-full justifyCtBwt"
                                             v-else-if="cartStoreInfo.defaultUseTicket.ticketType == 2">
                                            <div class="coupons-title">
                                                增值券
                                            </div>
                                            <div class="coupons-title">
                                                <span v-if="cartStoreInfo.defaultUseTicket.ticketContent.cashPrice">-￥{{cartStoreInfo.defaultUseTicket.ticketContent.cashPrice}}元</span>
                                                <span class="iconfont icon-arrows_left"></span>
                                            </div>
                                        </div>
                                        <div class="displayFlex width-full justifyCtBwt"
                                             v-else-if="cartStoreInfo.defaultUseTicket.ticketType == 3">
                                            <div class="coupons-title">
                                                折扣券
                                            </div>
                                            <div class="coupons-title">
                                                <span v-if="cartStoreInfo.defaultUseTicket.ticketContent.discount">{{cartStoreInfo.defaultUseTicket.ticketContent.discount}}折</span>
                                                <span class="iconfont icon-arrows_left"></span>
                                            </div>
                                        </div>
                                        <div class="displayFlex width-full justifyCtBwt"
                                             v-else-if="cartStoreInfo.defaultUseTicket.ticketType == 4">
                                            <div class="coupons-title">
                                                赠品券
                                            </div>
                                            <div class="coupons-title">
                                                <span v-if="cartStoreInfo.defaultUseTicket.ticketContent.gift">赠{{cartStoreInfo.defaultUseTicket.ticketContent.gift}}</span>
                                                <span class="iconfont icon-arrows_left"></span>
                                            </div>
                                        </div>
                                    </div>
                                    <!--TODO 优惠金额处理-->
                                    <div class="coupons-citem displayFlex width-full justifyCtBwt">
                                        <div class="coupons-title">
                                            优惠总金额
                                        </div>
                                        <div class="coupons-title">
                                            <span v-for="(countStore,index) in countStoreList" v-if="countStore.storeId == cartStoreInfo.storeId">-￥{{countStore.reduceTotalMoney}}元</span>
                                            <span class="iconfont icon-arrows_left"></span>
                                        </div>
                                    </div>
                                    <ul class="coupons-detail">
                                        <!--TODO 先不进行任何优惠券条件的处理-->
                                        <li class="coupons-detail-item" v-if="cartStoreInfo.defaultUseTicket && Object.keys(cartStoreInfo.defaultUseTicket).length > 0">
                                            <span v-if="cartStoreInfo.defaultUseTicket.ticketType == 1">
                                                <span v-if="">代金券</span>
                                                <span v-if="cartStoreInfo.defaultUseTicket.ticketContent && cartStoreInfo.defaultUseTicket.ticketContent.cashPrice">
                                                    -￥{{cartStoreInfo.defaultUseTicket.ticketContent.cashPrice}}
                                                </span>
                                            </span>
                                            <span v-if="cartStoreInfo.defaultUseTicket.ticketType == 2">
                                                <span v-if="">增值</span>
                                                <span v-if="cartStoreInfo.defaultUseTicket.ticketContent && cartStoreInfo.defaultUseTicket.ticketContent.increment">
                                                    ￥{{cartStoreInfo.defaultUseTicket.ticketContent.increment}}
                                                </span>
                                            </span>
                                            <span v-if="cartStoreInfo.defaultUseTicket.ticketType == 3">
                                                <span v-if="cartStoreInfo.defaultUseTicket.ticketContent && cartStoreInfo.defaultUseTicket.ticketContent.discount">{{cartStoreInfo.defaultUseTicket.ticketContent.discount}}折券</span>
                                                -￥<span>{{reduceMoneyFn(cartStoreInfo).discountReduceCash}}</span>
                                            </span>
                                            <span v-if="cartStoreInfo.defaultUseTicket.ticketType == 4">
                                                <span v-if="">赠</span>
                                                <span v-if="cartStoreInfo.defaultUseTicket.ticketContent && cartStoreInfo.defaultUseTicket.ticketContent.gift">
                                                    {{cartStoreInfo.defaultUseTicket.ticketContent.gift}}
                                                </span>
                                            </span>
                                            <!--优惠券-->
<!--                                            <span v-if="reduceInfo.reduceContent.valueType == 0">-￥{{reduceInfo.reduceContent.value}}</span>-->
                                            <!--折扣券-->
<!--                                            <span v-else-if="reduceInfo.reduceContent.valueType == 1">-￥{{reduceInfo.reduceContent.value * countMoney(cartStoreInfo.storeId)}}</span>-->
<!--                                            <span>{{reduceInfo.reduceContent.name}}</span>-->
                                        </li>
<!--                                         v-if="cartStoreInfo && Array.isArray(cartStoreInfo.reduceInfos) && cartStoreInfo.reduceInfos.length > 0"-->
                                        <li class="coupons-detail-item" v-for="reduceInfo in cartStoreInfo.reduceInfos">
                                            <span>{{reduceInfo.reduceContent.name}}</span>
                                            <!--优惠券-->
                                            <span v-if="reduceInfo.reduceContent.valueType == 0">-￥{{reduceInfo.reduceContent.value}}</span>
                                            <!--折扣券-->
                                            <span v-else-if="reduceInfo.reduceContent.valueType == 1">-￥{{reduceInfo.reduceContent.value * countMoney(cartStoreInfo.storeId)}}</span>
                                            <span>{{reduceInfo.reduceContent.name}}</span>
                                        </li>
                                    </ul>
                                </li>
                                <li class="cart-remark displayFlex">
                                    <span class="coupons-remark">备注</span>
                                    <span class="flex1">
                                    <textarea class="text-area" name="" id="" @blur="textareaBlur" placeholder="请输入备注信息" v-model="cartStoreInfo.leaveMessage" @change="changeLeaveMessage"></textarea>
                                </span>
                                </li>
                                <li class="cart-count" v-for="(countStore,index) in countStoreList" v-if="countStore.storeId == cartStoreInfo.storeId">
                                    <div class="send-money text-right"
                                         v-if="cartStoreInfo.expressFreight && Number(cartStoreInfo.expressFreight) > 0 && sendWay && sendWay.curDeliveryType == 1">
                                        运费：¥{{cartStoreInfo.expressFreight}}
                                    </div>
                                    <div class="cart-count-wmoney text-right">
                                        <span class="total-deposit" v-if="sendWay && sendWay.curDeliveryType == 0">定金小计: <span class="total-deposit-money">{{countStore.totalDeposit}}</span></span>
                                        订单小计：
                                        <span class="cart-count-money">
                                            <span class="fontSize12">￥</span>
                                            {{countStore.totalMoney}}
                                        </span>
                                    </div>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <!--失效订单-->
                <li :class="{'lose-order':Array.isArray(cartMoudleMsg.cartStoreInfos) && cartMoudleMsg.cartStoreInfos.length > 0}"
                    v-if="cartMoudleKey =='invalidStoreInfos' && cartMoudleItem && cartMoudleItem.length > 0">
                    <div class="store-list-wtitle displayFlex justifyCtBwt">
                        <span class="store-list-title">失效商品</span>
                        <span class="store-list-reson"
                              @click="batchDelete">清空所有失效商品{{cartMoudleItem.invalidItemInfos}}</span>
                    </div>
                    <ul class="sub-goods-list" v-for="cartStoreInfo in cartMoudleItem">
                        <li class="displayFlex sub-store-msg">
                            <div class="displayFlex flex-algin-center select-wImg">
                                <span v-if="cartMoudleKey == 'invalidStoreInfos'" class="disabled-select"></span>
                            </div>
                            <div class="flex1 displayFlex flex-algin-center justifyCtBwt">
                            <span class="displayFlex flex-algin-center ">
                                <span class="cart-userheader-wimg">
                                    <img class="cart-userheader-img positionAbCenter" :src="cartStoreInfo.storeLogo"
                                         alt="">
                                </span>
                                <span class="cart-user-name">{{cartStoreInfo.storeName}}</span>
                            </span>
                                <span v-if="cartMoudleKey == 'cartStoreInfos'">
                                <span v-if="cartStoreInfo.upportExpress" class="cart-send-way">支持快递与自提</span>
                                <span v-else class="cart-send-way">仅支持自提</span>
                            </span>
                            </div>
                        </li>
                        <li>
                            <div class="displayFlex cart-item" v-for="cartItemInfo in cartStoreInfo.invalidItemInfos">
                                <cell-swipe
                                        :right="[
                                    {
                                      content: '删除',
                                      style: { background: 'red', color: '#fff' ,width: '.6rem',},
                                      handler: ()=>deleteItem(cartStoreInfo.storeId,cartItemInfo.id,cartMoudleKey)
                                    }
                                  ]">
                                    <div class="cart-citem displayFlex">
                                        <div class="displayFlex flex-algin-center select-wImg">
                                            <span v-if="cartMoudleKey === 'invalidStoreInfos'"
                                                  class="disabled-select"></span>
                                        </div>
                                        <div class="cart-goods-wImg">
                                            <img class="cart-goods-img" v-lazy="cartItemInfo.itemImg" alt="">
                                        </div>
                                        <div class="flex1 displayFlex goods-msg flex-wrap">
                                            <div class="width-full">
                                                <h6 class="width-full two-line-ellepsis item-title">
                                                    {{cartItemInfo.title}}</h6>
                                                <!--这么暂时没有字段判断-->
                                                <span v-if="false"
                                                      class="warn-text displayBlock">此商品为定制商品，暂不支持退款！</span>
                                            </div>
                                            <div class="cart-goods-num displayFlex flex-algin-center width-full">
                                                <span v-if="cartItemInfo.invalidDesc"
                                                      class="flex1 fontSize12 color-gray-disabled">{{cartItemInfo.invalidDesc}}</span>
                                                <router-link
                                                        :to="{path:'/im/chat',query:{storeId:cartStoreInfo.storeId}}"
                                                        class="cart-send-way">联系客服
                                                </router-link>
                                            </div>
                                        </div>
                                    </div>
                                </cell-swipe>
                            </div>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
    /*使用mint-ui侧滑来删除购物车商品*/
    import {CellSwipe} from 'mint-ui';
    import {mapGetters} from 'vuex'
    export default {
        name: "SelectCart",
        props: {
            cartMoudleProp: Object,/*购物车模型*/
        },
        data() {
            return {
                selectList: [
                    // {
                    //     "itemId":124,       //-------购买的商品ID
                    //     "styleName":"a",    //-------购买的商品款式
                    //     "buyNum":2          //-------购买的商品数量
                    // },
                ],//将要提交到后台结算的list
                dicountList:[],//可用的优惠信息列表
                // storeTotalReduce:[
                //     // {
                //     //     storeId:0,
                //     //     reduce:0,
                //     // },
                // ],
                //总共减免金额
                countStoreList: [
                    // {
                    //     storeId: 0,//店铺id
                    //     reduceInfos: [//优惠信息
                    //         {
                    //             "name": "一起购优惠",       //-------优惠显示名字
                    //             "valueType": 0,             //-------优惠数值类型 0：金额  1：折扣
                    //             "value": "5",               //-------优惠数值
                    //         }
                    //     ],
                    //     curUseTicket: {//当前使用的优惠券信息
                    //         "ticketNum": "COOC5L99ZO",          //----------用户券号
                    //         "ticketType": 1,             //------优惠券类型 1: 代金券  2: 增值券 3:折扣券  4:赠品券
                    //         "ticketContent": {           //-----票的内容,详细参数 (券类型不同,内容不同)  @券的内容
                    //             "@class": "com.yibaotong.ms.nw.coupon.BO.user.content.ticket.TicketCashJson",
                    //             "limitConsume": false,
                    //             "consumePrice": "0",
                    //             "cashPrice": "100"
                    //         },
                    //         "state": 0,      //-------用户券状态，-2：失效，-1 :未开启 , 0 : 正常
                    //         "startTime": "19/07/19 11:18",       //-------生效时间
                    //         "endTime": "19/07/26 11:18",         //-------结束时间
                    //         "storeIcon": "https://oss.pg.yib/365d0.png",         //-------门店图标
                    //         "threshold": "无门槛直减",      //--------消费门槛展示文案
                    //         "scope": "全部商品可用",           //--------限定范围
                    //     },
                    //     totalMoney: 0,//此店铺订单小计
                    //     totalDeposit: 0,//此店铺订金小计
                    //     leaveMessage: 0,//留言信息
                    // }
                ],
                cartMoudleMsg: {
                    //  noSelectBtn:false, //是否不需要选择按钮
                    //  needDiscount:false, //是否需要显示优惠券信息
                    // "cartStoreInfos": [         //---------购物车店铺分类列表
                    //     {
                    //         "storeId": 102,
                    //         "storeName": "王者动物园",
                    //         "storeLogo": "https://oss.pg.yibaotong/fc1a365d0.png",
                    //         "supportExpress": true,             //---------是否支持快递
                    //         "selectAll": false, //是否本店所有商品选中
                    //         "cartItemInfos": [              //---------购物车内店铺商品列表
                    //             {
                    //                 "id": 1,        //----------购物车商品id,调删除接口时使用
                    //                 "selected": false, //是否选中
                    //                 "itemId": 124,
                    //                 "itemCode": "ddd",          //------------商品货号
                    //                 "itemTitle": "磕破一卡通卡关于推进\n\n\n",
                    //                 "price": "100",
                    //                 "quantity": 498,        //--------商品总库存
                    //                 "buyNum": 0,               //-----------购买数量 //TODO 这里暂时不支持多款同时购买，只能选一种款式购买
                    //                 "images": [
                    //                     "https://oss.pg.yibaoton/5967100.gif",
                    //                     "https://oss.pg.yib/432875100.png"
                    //                 ],
                    //                 "saleMode": 1,          //-----------售出方式 0-单款  1-多款
                    //                 "maxBuyNum": 5,          //------------个人可购买的最大数量(单款有效)
                    //                 "maxWarn": "此商品限购5件",          //------------超过最大购买数时的预警文案(单款有效)
                    //                 "itemServerals": [
                    //                     {
                    //                         "styleName": "a",               //-----------款名
                    //                         "styleImg": "https://oss.pg.yibao/100.png",         //-----------款式图
                    //                         "price": "100",         //-----------售价
                    //                         "quantity": 484,        //-----------款库存,为0则置灰
                    //                         "maxBuyNum": 5,         //------------个人可购买的最大数量
                    //                         "maxWarn": "此商品限购5件"         //------------超过最大购买数时的预警文案
                    //                     },
                    //                     {
                    //                         "styleName": "b",
                    //                         "styleImg": "https://oss.pgne/102975436100.png",
                    //                         "price": "2500",
                    //                         "quantity": 484,
                    //                         "maxBuyNum": 5,
                    //                         "maxWarn": "此商品限购5件"
                    //                     }
                    //                 ],
                    //                 "styleName": "a",       //---------当前选中的款式
                    //                 "price": "100",         //---------用户已选购的商品单价
                    //                 "buyNum": 2         //-----------购买数量
                    //             }
                    //         ]
                    //     }
                    // ],
                    // "invalidStoreInfos": [          //------失效的店铺商品列表
                    //     {
                    //         "storeId": 102,
                    //         "storeName": "王者动物园",
                    //         "storeLogo": "https://oss.pg.yiba/365d0.png",
                    //         "invalidItemInfos": [
                    //             {
                    //                 "id": 2,            //----------购物车商品id
                    //                 "itemId": 2223,
                    //                 "itemImg": "https://oss.pg.y/854100.png",
                    //                 "title": "联系我哦",
                    //                 "invalidDesc": "宝贝已下架"        //-------------失效描述
                    //             }
                    //         ]
                    //     }
                    // ]
                }
            }
        },
        computed:{
            ...mapGetters({
                sendWay:'getSendWayMsg'
            })
        },
        mounted() {
            let that = this;
            this.cartMoudleMsg = Object.assign({}, this.cartMoudleMsg, this.cartMoudleProp)
            /*初始化页面商品优惠信息*/
            if(Object.keys(this.cartMoudleMsg).length > 0){
                this.initStoreList();
            }
        },
        methods: {
            changeInputNumber(val, storeId, itemId) {
                let that = this;
                that.cartMoudleMsg.cartStoreInfos.forEach((cartStoreInfosValue, cartStoreInfosIndex) => {
                    if (cartStoreInfosValue.storeId == storeId) {
                        cartStoreInfosValue.cartItemInfos.forEach((cartItemInfosValue, cartItemInfosIndex) => {
                            if (cartItemInfosValue.itemId == itemId) {
                                that.cartMoudleMsg.cartStoreInfos[cartStoreInfosIndex].cartItemInfos[cartItemInfosIndex].buyNum = val;
                            }
                        })
                    }
                })
                /*TODO 刷新优惠信息和优惠券信息，然后才能刷新金额*/
                // this.refreshDiscount()
                // this.refreshDiscount()
                this.refreshBuyBar(storeId);
            },
            changeNum(obj) {
            },
            textareaBlur(){
                var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                this.iosBlur('auto',scrollTop);
            },
            deleteItem(storeId, itemId, deleteType) {
                let delelteObj = {
                    storeId,
                    selectItemId: itemId,
                    deleteType,
                }
                this.$emit("deleteItem", delelteObj);
            },
            /*修改留言*/
            changeLeaveMessage(){
                console.log();
                this.$emit('freshCartMoudleMsg',this.cartMoudleMsg);
            },
            /*选择某个店铺下面所有的商品*/
            selectStore(storeId, isSelected) {
                let that = this;
                this.cartMoudleMsg.cartStoreInfos.forEach((value, index) => {
                    if (value.storeId == storeId) {
                        isSelected = !isSelected;
                        that.cartMoudleMsg.cartStoreInfos[index].selectAll = isSelected;
                        value.cartItemInfos.forEach((cartItemValue, cartItemIndex) => {
                            that.cartMoudleMsg.cartStoreInfos[index].cartItemInfos[cartItemIndex].selected = isSelected;
                        })
                    }
                })
                that.cartMoudleMsg.cartStoreInfos.splice(0, 1, that.cartMoudleMsg.cartStoreInfos[0])
                /*是否全选*/
                this.isSelectAll();
                /*刷新购买商品的价格*/
                this.refreshBuyBar();
            },
            getCountMsg(cartItemInfo, storeId) {
                let countMsg = {};
                let maxBuyNum = 0;
                let maxBuyWarn = '';
                // 库存不需要前端处理 if (cartItemInfo.maxBuyNum && cartItemInfo.maxBuyNum > 0 && cartItemInfo.maxBuyNum <= cartItemInfo.quantity) {
                if (cartItemInfo.maxBuyNum && cartItemInfo.maxBuyNum > 0) {
                    maxBuyNum = cartItemInfo.maxBuyNum;
                    maxBuyWarn = cartItemInfo.maxWarn;
                    /*库存不足不会显示*/
                } else if (!cartItemInfo.maxBuyNum) {
                    maxBuyNum = 0;
                    if (cartItemInfo.quantity) {
                        maxBuyNum = cartItemInfo.quantity;
                    }
                    maxBuyWarn = '商品库存不足';
                } else {
                    maxBuyNum = 0;
                    maxBuyWarn = cartItemInfo.maxWarn || '商品库存不足';
                }
                if (cartItemInfo.maxBuyNum && cartItemInfo.maxBuyNum > 0) {
                    countMsg = {
                        maxLimit: {
                            isLimit: !!cartItemInfo.maxBuyNum,
                            num: maxBuyNum,
                            text: maxBuyWarn,
                            showTime: 1000,
                        },
                        minLimit: {
                            isLimit: true,
                            num: 1,
                            text: '最低选一件商品',
                            showTime: 1000,
                        },
                        storeId: storeId,
                        itemId: cartItemInfo.itemId,
                    }
                }
                return countMsg;
            },
            //是否全选了
            isSelectAll() {
                let that = this;
                let allStoreSelected = true;
                that.cartMoudleMsg.cartStoreInfos.forEach((value, index) => {
                    if (!value.selectAll) {
                        allStoreSelected = false;
                    }
                });
                that.$emit('isSelectAll', allStoreSelected);
            },
            /*选取单个商品*/
            selectItem(storeId, itemId, isSelected) {
                let that = this;
                let selectLength = 0;
                let cartStoreInfosLength = 0;
                this.cartMoudleMsg.cartStoreInfos.forEach((value, index) => {
                    if (value.storeId == storeId) {
                        cartStoreInfosLength = value.cartItemInfos.length;
                    }
                });
                this.cartMoudleMsg.cartStoreInfos.forEach((value, index) => {
                    if (value.storeId == storeId) {
                        // that.cartMoudleMsg.cartStoreInfos[index].selectAll = isSelected;
                        value.cartItemInfos.forEach((cartItemValue, cartItemIndex) => {
                            if (itemId === cartItemValue.itemId) {
                                that.cartMoudleMsg.cartStoreInfos[index].cartItemInfos[cartItemIndex].selected = !isSelected;
                                let itemSelelted = that.cartMoudleMsg.cartStoreInfos[index].cartItemInfos[cartItemIndex].selected;
                                if (itemSelelted) {
                                    selectLength++;
                                }
                            } else if (cartItemValue.selected) {
                                selectLength++;
                            }
                        })
                        if (selectLength == cartStoreInfosLength) {
                            that.cartMoudleMsg.cartStoreInfos[index].selectAll = true;
                        } else {
                            that.cartMoudleMsg.cartStoreInfos[index].selectAll = false;
                        }
                    }
                    that.cartMoudleMsg.cartStoreInfos.splice(0, 1, that.cartMoudleMsg.cartStoreInfos[0])
                })
                /*是否全选*/
                this.isSelectAll();
                /*刷新购买商品的价格*/
                this.refreshBuyBar();
            },
            refreshBuyBar(storeId) {
                let that = this;
                let totalGoodsMoney = 0;
                let totalShippingFee = 0;//邮费这个现在暂时好像还没有做（都是免邮的吧）
                this.cartMoudleMsg.cartStoreInfos.forEach((cartStoreInfosValue, cartStoreInfosIndex) => {
                    that.discountMsgDeal(cartStoreInfosValue);
                    totalShippingFee += cartStoreInfosValue.expressFreight || 0;
                    cartStoreInfosValue.cartItemInfos.forEach((cartItemInfosValue, cartItemInfosIndex) => {
                        if (cartItemInfosValue.selected) {
                            totalGoodsMoney += cartItemInfosValue.buyNum * cartItemInfosValue.price
                        }
                    })
                });
                /*修改小计和总计以及优惠信息*/
                let tempObj = {};
                if(this.cartMoudleMsg.noSelectBtn){
                    this.closeAccountMsg();
                }else{
                    tempObj = {
                        payMoney: {
                            money: totalGoodsMoney,
                            text: '总额'
                        },
                        shippingFee: {
                            isShow: true,
                            money: totalShippingFee,
                        },//邮费、配送费用 ,//邮费、配送费用
                    }
                    this.$emit('refreshBuyBar', tempObj);
                }
            },
            /*接收到来的父组件传过来的数据之后需要再进行一次数据的转换，用于前端数据的展示又不能改变原来的数据*/
            initStoreList() {
                let that  = this;
                this.cartMoudleMsg.cartStoreInfos.forEach((cartStoreInfoValue, cartStoreInfoIndex) => {
                    that.discountMsgDeal(cartStoreInfoValue);
                })
            },
            /*所有订单的定金和尾款总计*/
            closeAccountMsg(){
                let accountTotalMoney = 0;//店铺总金额
                let accountTotalDeposit = 0;//店铺总保证金
                let accountTotalDiscount = 0;//店铺总优惠
                let accountTotalExpressFreight = 0;//店铺总运费
                this.countStoreList.forEach((countStoreValue,countStoreIndex)=>{
                    accountTotalMoney += countStoreValue.totalMoney;
                    accountTotalDeposit += countStoreValue.totalDeposit;
                    accountTotalExpressFreight += countStoreValue.expressFreight;
                    /*TODO 店铺总优惠*/
                })
                accountTotalMoney = Math.floor((accountTotalMoney) * 100) / 100;
                accountTotalDeposit = Math.ceil((accountTotalDeposit) * 100) / 100;
                let finalPayment = Math.ceil((accountTotalMoney - accountTotalDeposit) * 100) / 100;
                let expressFreight = Math.ceil((accountTotalExpressFreight) * 100) / 100;
                let payMoneyText = '定金';
                let tempObj = {
                    payMoney:{
                        money:accountTotalDeposit,
                        text:payMoneyText
                    },//商品总金额
                    btnText:'去支付',
                    deposit:{//尾款
                        isShow:true,
                        money:finalPayment,
                    },
                    shippingFee:{
                        isShow:false,
                        money:expressFreight,
                    }
                }
                /*快递的时候字体是总额*/
                if(this.sendWay && this.sendWay.curDeliveryType == 1){
                    payMoneyText = '总额';
                    tempObj = {
                        payMoney:{
                            money:accountTotalMoney,
                            text:payMoneyText
                        },//商品总金额
                        btnText:'去支付',
                        deposit:{//尾款
                            isShow:false,
                            money:finalPayment,
                        },
                        shippingFee:{
                            isShow:true,
                            money:expressFreight,
                        }
                    }
                }
                this.$emit('refreshBuyBar',tempObj);
            },
            /*优惠信息，需要处理*/
            reduceMoneyFn(cartStoreInfo) {
                /*优惠券两种情况一种满减券，另外一种折扣券，增值券暂时没做，这里只考虑优惠券的形式*/
                /*优惠信息加上优惠券上面的总优惠就是优惠总金额*/
                let that = this;
                let tempObj = {};
                let tempReduceList = [];
                let reduceTotalMoney = 0;
                if(Array.isArray(cartStoreInfo.reduceInfos) && cartStoreInfo.reduceInfos.length > 0){
                    cartStoreInfo.reduceInfos.forEach((reduceInfoValue,reduceInfoIndex)=>{
                        if(reduceInfoValue.conditions){
                            /*当前店铺的非优惠券所优惠的优惠金额之和*/
                            /*满足限制条件的优惠信息*/
                            cartStoreInfo.reduceInfos.forEach((cartStoreValue,index)=>{
                                /*有限制条件，并且限制条件不为空*/
                                let isNotMeetConditions = true;
                                let meetConditionsLength = 0;
                                if( Array.isArray(cartStoreValue.conditions) && cartStoreValue.conditions.length > 0){
                                    cartStoreValue.conditions.forEach((conditionValue,conditionIndex)=>{
                                        /*当前店铺购买的商品里面是否有这个商品，全部满足条件的话才能使用这个优惠*/
                                        /*是否有满足条件的商品*/
                                        let hasMeetConditionGoods = false;
                                        cartStoreInfo.cartItemInfos.forEach((cartIteminfo,cartItemValue)=>{
                                            /*有限制条件*/
                                            if(cartStoreValue.itemId){
                                                if(cartStoreValue.styleName){
                                                    /*有一个条件没有满足就不能使用*/
                                                    if(cartStoreValue.itemId == cartIteminfo.itemId && cartStoreValue.styleName  == cartIteminfo.styleName){
                                                        hasMeetConditionGoods = true;
                                                    }
                                                }else{
                                                    if(cartStoreValue.itemId == cartIteminfo.itemId){
                                                        hasMeetConditionGoods = true;
                                                    }
                                                }
                                                /*没有限制条件*/
                                            }else{
                                                hasMeetConditionGoods = true;
                                            }
                                            /*如果有符合条件的商品就计数，最后算总数*/
                                            if(hasMeetConditionGoods){
                                                meetConditionsLength ++
                                            }
                                        })
                                        /*符合条件的个数相同就表示这个优惠信息可用*/
                                        if(meetConditionsLength == cartStoreInfo.cartItemInfos.length){
                                            /*计算符合条件的价格*/
                                            /*金额直接减，但是不能超过商品的价格，所以要循环商品的价格才知道减多少*/
                                            let reduceMoney = 0;
                                            let reduceGoodsTotalPrice = 0;
                                                if( Array.isArray(cartStoreValue.targetItemIds) && cartStoreValue.targetItemIds.length ){
                                                    cartStoreValue.targetItemIds.forEach((targetItemId,targetItemValue)=>{
                                                        cartStoreInfo.cartItemInfos.forEach((cartIteminfo)=>{
                                                            conosole.log();
                                                            if(cartIteminfo.itemId == targetItemId){
                                                                /*是否可叠加数量*/
                                                                if(cartStoreValue.accumulative){
                                                                    reduceGoodsTotalPrice += Number(cartIteminfo.price) * Number(cartIteminfo.buyNum)
                                                                }else{
                                                                    reduceGoodsTotalPrice += Number(cartIteminfo.price)
                                                                }
                                                            }
                                                        })
                                                    })
                                                }

                                            /*如果减免金额大于可享受优惠的商品总金额，减免金额就为商品总金额，如果不是就是自己的金额*/
                                            /*为减免的金额的时候*/
                                            if(cartStoreValue.valueType == 0){
                                                if(reduceGoodsTotalPrice > cartStoreValue.value){
                                                    reduceMoney = Number(cartStoreValue.value)
                                                }else{
                                                    reduceMoney = reduceGoodsTotalPrice;
                                                }
                                            /*为折扣的时候*/
                                            }else if(cartStoreValue.valueType == 1){
                                                let reduceDiscount = Number(cartStoreValue.value) * reduceGoodsTotalPrice
                                                if(reduceDiscount > reduceGoodsTotalPrice){
                                                    reduceMoney = reduceGoodsTotalPrice
                                                }else{
                                                    reduceMoney = reduceDiscount;
                                                }
                                            }
                                            tempObj = {
                                                reduceMoney:reduceMoney,
                                                name:cartStoreValue.name
                                            };
                                            that.dicountList.push(tempObj);
                                        }
                                    })
                                    /*没有限制条件，直接使用计算优惠信息已经金额*/
                                }else{
                                    /*计算符合条件的价格*/
                                    /*金额直接减，但是不能超过商品的价格，所以要循环商品的价格才知道减多少*/
                                    let reduceMoney = 0;
                                    let reduceGoodsTotalPrice = 0;
                                    if( Array.isArray(cartStoreValue.targetItemIds) && cartStoreValue.targetItemIds.length ){
                                        cartStoreValue.targetItemIds.forEach((targetItemId,targetItemValue)=>{
                                            cartStoreInfo.cartItemInfos.forEach((cartIteminfo)=>{
                                                conosole.log();
                                                if(cartIteminfo.itemId == targetItemId){
                                                    /*是否可叠加数量*/
                                                    if(cartStoreValue.accumulative){
                                                        reduceGoodsTotalPrice += Number(cartIteminfo.price) * Number(cartIteminfo.buyNum)
                                                    }else{
                                                        reduceGoodsTotalPrice += Number(cartIteminfo.price)
                                                    }
                                                }
                                            })
                                        })
                                    }

                                    /*如果减免金额大于可享受优惠的商品总金额，减免金额就为商品总金额，如果不是就是自己的金额*/
                                    /*为减免的金额的时候*/
                                    if(cartStoreValue.valueType == 0){
                                        if(reduceGoodsTotalPrice > cartStoreValue.value){
                                            reduceMoney = Number(cartStoreValue.value)
                                        }else{
                                            reduceMoney = reduceGoodsTotalPrice;
                                        }
                                        /*为折扣的时候*/
                                    }else if(cartStoreValue.valueType == 1){
                                        let reduceDiscount = Number(cartStoreValue.value) * reduceGoodsTotalPrice
                                        if(reduceDiscount > reduceGoodsTotalPrice){
                                            reduceMoney = reduceGoodsTotalPrice
                                        }else{
                                            reduceMoney = reduceDiscount;
                                        }
                                    }
                                    tempObj = {
                                        reduceMoney:reduceMoney,
                                        name:cartStoreValue.name
                                    };
                                    that.dicountList.push(tempObj);
                                }
                            })
                            console.log(reduceInfoValue);
                        }
                    });
                }
                /*这里还有另外几种优惠，0:一起购优惠  1:优惠券 2:会员折扣 3:会员积分抵现 4:团长优惠  5:排名优惠  6:抽奖中奖优惠 7:红包抵扣*/
                // return tempReduceList;
                /*减免总金额除了要加减免信息金额还需要加优惠券减免的金额*/
                that.dicountList.forEach((value,index)=>{
                    reduceTotalMoney += value.reduceMoney;
                })
                //优惠券类型 1: 代金券  2: 增值券 3:折扣券  4:赠品券
                //只考虑代金券和折扣券的情况
                let discountDefaultMoney = 0;
                let discountReduceCash = 0;
                cartStoreInfo.cartItemInfos.forEach((cartItemInfoValue,cartItemInfoIndex)=>{
                    discountDefaultMoney += Number(cartItemInfoValue.price) * Number(cartItemInfoValue.buyNum);
                });
                if(cartStoreInfo.defaultUseTicket && cartStoreInfo.defaultUseTicket.ticketType == 1){
                    try{
                        /*减免金额大于商品总金额*/
                        if(cartStoreInfo.defaultUseTicket.ticketContent.cashPrice > discountDefaultMoney){
                            discountReduceCash = discountDefaultMoney;
                        }else{
                            discountReduceCash = Number(cartStoreInfo.defaultUseTicket.ticketContent.cashPrice);
                        }
                    }catch (e) {
                    }
                }else if(cartStoreInfo.defaultUseTicket && cartStoreInfo.defaultUseTicket.ticketType == 3){
                    try{
                        let tempMoney = Number(cartStoreInfo.defaultUseTicket.ticketContent.discount) * discountDefaultMoney / 100;
                        /*减免金额大于商品总金额*/
                        if(tempMoney > discountDefaultMoney){
                            discountReduceCash = discountDefaultMoney;
                        }else{
                            discountReduceCash = tempMoney;
                        }
                    }catch (e) {
                    }
                }
                reduceTotalMoney += discountReduceCash;
                // let tempTotalReduceObj = {
                //     storeId:cartStoreInfo.storeId,
                //     reduce:reduceTotalMoney,
                // }
                // let existStore = false;
                // let replaceIndex = -1;
                /*如果减免信息里面包含了当前店铺的减免信息就替换，没有包含就直接push*/
                // if(Array.isArray(this.storeTotalReduce) && this.storeTotalReduce.length > 0){
                //     this.storeTotalReduce.forEach((value,index)=>{
                //         if(value.storeId == cartStoreInfo.storeId){
                //             existStore = true;
                //             replaceIndex = index;
                //         }
                //     })
                // }
                // if(!existStore){
                //     that.storeTotalReduce.push(tempTotalReduceObj);
                // }else{
                //     that.storeTotalReduce.splice(replaceIndex,1,tempTotalReduceObj);
                // }
                return {discountReduceCash,reduceTotalMoney};
            },
            /*优惠信息已经相关信息处理*/
            discountMsgDeal(cartStoreInfoValue) {
                // 订单金额计算：
                // 商品购买金额：itemPrice = 单价*数量
                // 店铺商品总价：storeTotlePrice = itemPrice 之和
                // 店铺商品订单总额：店铺商品总价 - 优惠总额
                // 保证金金额：(商品购买金额*商品保证金比例) 之和；算出的结果如果大于店铺订单总额，则取店铺订单总额
                // 需要判断当前优惠券是否可使用的情况： 修改商品款式|购买数量|修改配送
                // 点击打开优惠券列表需要重新分类计算
                // reduceInfo.reduceContent.valueType == 1
                // this.storeIncludeGoodsIdsProp = '';

                /*当前选中店铺*/
                let that = this;
                let reduceTotalMoney = 0;//优惠总金额
                let totalMoney = 0;//商品单价和商品数量的总计金额（不包括计算优惠信息和运费的情况）
                let totalDeposit = 0;//单个店铺总保证金
                let totolExpressFreight = 0;//总运费
                let reduceInfosObj = {};
                let canUseDiscounts = [];
                let tempObj = {
                    // "name": "一起购优惠",       //-------优惠显示名字
                    // "valueType": 0,             //-------优惠数值类型 0：金额  1：折扣
                    // "value": "5",               //-------优惠数值
                };
                /*优惠信息的处理,非优惠券*/
                let discountMsg = 0
                try {
                    discountMsg = that.reduceMoneyFn(cartStoreInfoValue).reduceTotalMoney;
                }catch (e) {
                    discountMsg = 0;
                }
                /*临时的优惠信息*/
                let tempCountStore = {
                    storeId: 0,//店铺id
                    reduceInfos: [//优惠信息
                        // {
                        //     "name": "一起购优惠",       //-------优惠显示名字
                        //     "valueType": 0,             //-------优惠数值类型 0：金额  1：折扣
                        //     "value": "5",               //-------优惠数值
                        // }
                    ],
                    curUseTicket:{},
                    totalMoney: 0,//此店铺订单小计 //计算完成之后的总金额
                    totalDeposit: 0,//此店铺订金小计
                    expressFreight:0,//总运费
                    leaveMessage: '',//留言信息
                    reduceTotalMoney:discountMsg || 0,

                };
                /*计算总价格*/
                /*选择自提可以先付定金，选择快递就需要一次性支付所有金额*/
                if(this.sendWay.curDeliveryType == 1 && cartStoreInfoValue.expressFreight && (cartStoreInfoValue.supportExpress || cartStoreInfoValue.supportExpress == 'true')  ){
                    cartStoreInfoValue.cartItemInfos.forEach((cartItemInfoValue, cartItemInfoIndex) => {
                        totalMoney += cartItemInfoValue.price * cartItemInfoValue.buyNum;
                    })
                    totalMoney += Number(cartStoreInfoValue.expressFreight) - discountMsg;
                    totalDeposit = totalMoney;
                }else{
                    cartStoreInfoValue.cartItemInfos.forEach((cartItemInfoValue, cartItemInfoIndex) => {
                        totalMoney += cartItemInfoValue.price * cartItemInfoValue.buyNum;
                        totalDeposit += cartItemInfoValue.price * cartItemInfoValue.buyNum * cartItemInfoValue.depositRate;
                    })
                    totalMoney -= discountMsg
                }
                totolExpressFreight = cartStoreInfoValue.expressFreight || 0;
                // console.log('cartStoreInfoValue')
                // console.log(cartStoreInfoValue)
                /*循环优惠信息，判断哪个可用哪个不可用*/
                if( Array.isArray(cartStoreInfoValue.reduceInfos) && cartStoreInfoValue.reduceInfos.length > 0){
                    cartStoreInfoValue.reduceInfos.forEach((reduceInfoValue, reduceInfoIndex) => {
                        reduceInfosObj = {};
                        /*没有限制条件*/
                        if (!(Array.isArray(reduceInfoValue.conditions) && reduceInfoValue.conditions.length > 0)) {
                            /*判断具体哪个商品享受优惠*/
                            /*没有限制具体哪一对商品可以享受优惠，则每一个商品都可享受优惠折扣，也可享受减免优惠金额*/
                            if (!(Array.isArray(reduceInfoValue.reduceContent.targetItemIds) && reduceInfoValue.reduceContent.targetItemIds.length > 0)) {
                                /*是可叠加*/
                                /*优惠类型 0 金额  1 折扣*/
                                if (reduceInfoValue.reduceContent.valueType == 0) {
                                    reduceTotalMoney += reduceInfoValue.reduceContent.value;
                                } else if (reduceInfoValue.reduceContent.valueType == 1) {
                                    /*当前店铺所有商品价值总额 * 折扣 , 优惠列表中，不应该有几个折扣券，如果有，将会累积计算，导致优惠信息过多*/
                                    reduceTotalMoney += reduceInfoValue.reduceContent.value * totalMoney;
                                }
                            } else {
                                /*限制了具体那一对商品可以享受优惠*/
                                let totalAPairMoney = 0;
                                let buyNumArray = [];
                                reduceInfoValue.reduceContent.targetItemIds.forEach((targetItemId, index) => {
                                    cartStoreInfoValue.cartStoreInfos.forEach((goodsListValue, goodsListIndex) => {
                                        /*包含此商品，如果不包含不进行优惠的计算*/
                                        if (goodsListValue.itemId == targetItemId) {
                                            totalAPairMoney += goodsListValue.price * goodsListValue.buyNum;
                                            buyNumArray.push(goodsListValue.buyNum);
                                        }
                                    });
                                });
                                let min = Math.min.apply(null, buyNumArray);
                                /*是否可叠加*/
                                /*折扣券一般是没有叠加的*/
                                if (reduceInfoValue.reduceContent.accumulative) {
                                    /*可以叠加的优惠计算方式*/
                                    /*优惠类型 0 金额  1 折扣*/
                                    if (reduceInfoValue.reduceContent.valueType == 0) {
                                        reduceTotalMoney += reduceInfoValue.reduceContent.value * min;
                                    } else if (reduceInfoValue.reduceContent.valueType == 1) {
                                        reduceTotalMoney += reduceInfoValue.reduceContent.value * totalAPairMoney * min;
                                    }
                                } else {
                                    /*只能有一次优惠的结算方式*/
                                    /*优惠类型 0 金额  1 折扣*/
                                    if (reduceInfoValue.reduceContent.valueType == 0) {
                                        reduceTotalMoney += reduceInfoValue.reduceContent.value;
                                    } else if (reduceInfoValue.reduceContent.valueType == 1) {
                                        reduceTotalMoney += reduceInfoValue.reduceContent.value * totalAPairMoney;
                                    }
                                }
                            }
                            reduceInfosObj = reduceInfoValue
                        } else {
                            /*处理优惠券的限制条件*/
                            let discountContentLength = 0;
                            if(reduceInfoValue.conditions){

                            }
                            reduceInfoValue.conditions.forEach((conditionValue, conditionsIndex) => {
                                if(cartStoreInfoValue.cartStoreInfos){
                                    cartStoreInfoValue.cartStoreInfos.forEach((goodsListValue, goodsListIndex) => {
                                        if (goodsListValue.itemId == conditionValue.itemId && goodsListValue.styleName == conditionValue.styleName) {
                                            /*此商品满足限制条件，可以使用此优惠，可以进行优惠信息显示与添加*/
                                            discountContentLength++;
                                        }
                                    });
                                }

                            })
                            /*同时满足了所有条件，可以有此优惠*/
                            /*优惠券内容*/
                            if (discountContentLength == reduceInfoValue.conditions.length) {
                                /*判断具体哪个商品享受优惠*/
                                /*没有限制具体哪一对商品可以享受优惠，则每一个商品都可享受优惠折扣，也可享受减免优惠金额*/
                                if (!(Array.isArray(reduceInfoValue.reduceContent.targetItemIds) && reduceInfoValue.reduceContent.targetItemIds.length > 0)) {
                                    /*是可叠加*/
                                    /*优惠类型 0 金额  1 折扣*/
                                    if (reduceInfoValue.reduceContent.valueType == 0) {
                                        reduceTotalMoney += reduceInfoValue.reduceContent.value
                                    } else if (reduceInfoValue.reduceContent.valueType == 1) {
                                        /*当前店铺所有商品价值总额 * 折扣 , 优惠列表中，不应该有几个折扣券，如果有，将会累积计算，导致优惠信息过多*/
                                        reduceTotalMoney += reduceInfoValue.reduceContent.value * totalMoney;
                                    }
                                } else {
                                    /*限制了具体那一对商品可以享受优惠*/
                                    let totalAPairMoney = 0;
                                    let buyNumArray = [];

                                    reduceInfoValue.reduceContent.targetItemIds.forEach((targetItemId, index) => {
                                        cartStoreInfoValue.cartStoreInfos.forEach((goodsListValue, goodsListIndex) => {
                                            /*包含此商品，如果不包含不进行优惠的计算*/
                                            if (goodsListValue.itemId == targetItemId) {
                                                totalAPairMoney += goodsListValue.price * goodsListValue.buyNum;
                                                buyNumArray.push(goodsListValue.buyNum);
                                            }
                                        });
                                    });
                                    let min = Math.min.apply(null, buyNumArray);
                                    /*是否可叠加*/
                                    /*折扣券一般是没有叠加的*/
                                    if (reduceInfoValue.reduceContent.accumulative) {
                                        /*可以叠加的优惠计算方式*/
                                        /*优惠类型 0 金额  1 折扣*/
                                        if (reduceInfoValue.reduceContent.valueType == 0) {
                                            reduceTotalMoney += reduceInfoValue.reduceContent.value * min;
                                        } else if (reduceInfoValue.reduceContent.valueType == 1) {
                                            reduceTotalMoney += reduceInfoValue.reduceContent.value * totalAPairMoney * min;
                                        }
                                    } else {
                                        /*只能有一次优惠的结算方式*/
                                        /*优惠类型 0 金额  1 折扣*/
                                        if (reduceInfoValue.reduceContent.valueType == 0) {
                                            reduceTotalMoney += reduceInfoValue.reduceContent.value;
                                        } else if (reduceInfoValue.reduceContent.valueType == 1) {
                                            reduceTotalMoney += reduceInfoValue.reduceContent.value * totalAPairMoney;
                                        }
                                    }
                                }
                                reduceInfosObj = reduceInfoValue
                            } else {
                                /*未满足所有优惠信息，不可使用该优惠，不进行任何优惠信息的计算*/
                            }
                        }
                        /*只有此条优惠信息满足限制条件或者没有限制条件才能使用*/
                        if (Object.keys(reduceInfosObj).length > 0) {
                            tempCountStore.reduceInfos.push(reduceInfosObj);
                        }

                    });
                }
                /*总金额需要判断是否需要快递然后计算总运费*/
                tempCountStore.totalMoney = parseInt( ( totalMoney - reduceTotalMoney ) * 100 ) / 100  ;
                tempCountStore.totalDeposit = parseInt( totalDeposit * 100) / 100 ;
                tempCountStore.storeId = cartStoreInfoValue.storeId;
                tempCountStore.expressFreight = totolExpressFreight;
                /*保证同一个店铺只push一次*/
                if (Array.isArray(that.countStoreList) && that.countStoreList.length > 0) {
                    let tempI = 0;
                    that.countStoreList.forEach((countStoreValue, countStoreIndex) => {
                        if (countStoreValue.storeId == cartStoreInfoValue.storeId) {
                            that.countStoreList.splice(countStoreIndex, 1, tempCountStore);
                        }else{
                            tempI ++ ;
                        }
                    });
                    if( tempI == that.countStoreList.length ){
                        that.countStoreList.push(tempCountStore)
                    }
                } else {
                    that.countStoreList.push(tempCountStore)
                }
                /*计算底部按钮的小计和总价格以及尾款*/
                that.closeAccountMsg();
            },
            /*点击加减判断优惠券的使用情况*/
            changeDiscount() {

            },
            /*计算单个店铺的订单的总金额*/
            countMoney(storeId) {
                let oneStoreMoney = 0;
                this.cartMoudleMsg.cartStoreInfos.forEach((value, index) => {
                    if (storeId == value.storeId) {
                        value.cartItemInfos.forEach((value, index) => {
                            oneStoreMoney += value.price * value.buyNum
                        })
                    }
                })
                return oneStoreMoney;
            },
            /*批量删除购物车失效商品，这个接口也可以用于删除正常，只不过产品没有弄批量删除的需求*/
            batchDelete() {
                let tempArray = [];
                let deleteArray = [];
                let that = this;
                for (let index in that.cartMoudleMsg) {
                    if (index == 'invalidStoreInfos') {
                        tempArray = that.cartMoudleMsg[index]
                        tempArray.forEach((value, cartMoudleMsgIndex) => {
                            if (Array.isArray(value.invalidItemInfos)) {
                                value.invalidItemInfos.forEach((value, itemIndex) => {
                                    deleteArray.push(value.id)
                                })
                            }
                        })
                    }
                }
                if (deleteArray.length > 0) {
                    this.$emit('batchDelete', deleteArray);
                }
            }
        },
        watch: {
            cartMoudleProp(val, oldVal) {
                this.cartMoudleMsg = Object.assign({}, this.cartMoudleMsg, val);
                /*初始化页面商品优惠信息*/
                if(Object.keys(this.cartMoudleMsg).length > 0){
                    this.initStoreList();
                }
                console.log(this.cartMoudleMsg,'111111111111111111')
                if (this.cartMoudleMsg.length > 0) {
                    this.cartMoudleMsg.cartStoreInfos.splice(0, 1, this.cartMoudleMsg.cartStoreInfos[0]);
                }
            },
        },
        components: {
            'countor': () => import('../../../components/commonComponents/countor/Countor'),
            "no-data": () => import("../../../components/commonActModel/noData/NoData"),
            'cell-swipe': CellSwipe,
        }
    }
</script>

<style scoped lang="scss">
    .sub-store-list /deep/ {
        .mint-cell-value {
            width: 100%;
        }
        .mint-cell-swipe-buttongroup{
            width: 101%;
        }
        .mint-cell-wrapper {
            padding: 0;
        }

        .mint-cell-swipe-button {
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: .14rem;
        }

        .mint-cell-swipe {
            width: 100%;
            height: 100%;
        }

    }

    .select-cart /deep/ {
        .no-wcomment {
            z-index: 1;
            height: 5.77rem;
            height: 80vh;
            height: calc(100vh - .9rem);
        }
    }

    .cart-citem {
        width: 100%;
        padding: .1rem 0;
    }

    .sub-store-list {
        background-color: #fff;
    }

    .cart-userheader-img {
        height: .24rem;
        width: .24rem;
        object-fit: unset;
        border-radius: 50%;
    }

    .cart-userheader-wimg {
        height: .24rem;
        width: .24rem;
        position: relative;
        display: inline-block;
        margin-right: .08rem;
    }

    .sub-store-msg {
        line-height: .24rem;
        align-items: center;
        padding-top: .15rem;
        border-bottom: 0;
    }

    .cart-send-way {
        color: #5D89E8;
        font-size: .12rem;
    }

    .select-img {
        position: relative;
        width: .16rem;
    }

    .disabled-select {
        display: inline-block;
        width: .16rem;
        height: .16rem;
        -webkit-border-radius: 50%;
        -moz-border-radius: 50%;
        border-radius: 50%;
        background-color: #F0F0F0;
    }

    .select-wImg {
        margin-right: .05rem;
    }

    .sub-goods-list {
        border-bottom: 1px solid #f0f0f0;
        padding: 0 .15rem;
        &:nth-last-child(1){
            margin-bottom: .9rem;
        }
    }

    .cart-goods-img {
        width: 1.2rem;
        height: 1.7rem;
        object-fit: cover;
        border-radius: .05rem;
    }

    .cart-goods-wImg {
        width: 1.2rem;
        height: 1.7rem;
        margin-right: .16rem;
    }

    .cart-goods-style {
        padding: .01rem .1rem;
        background-color: #f0f0f0;
        font-size: .12rem;
        color: #999;
        -webkit-border-radius: .12rem;
        -moz-border-radius: .12rem;
        border-radius: .12rem;
    }

    .warn-text {
        padding-top: .1rem;
        font-size: .11rem;
        color: #FF3333;
    }

    .item-title {
        margin-bottom: .15rem;
        color: #333;
        line-height: .15rem;
    }

    .store-list-title {
        font-size: .15rem;
        color: #666666;
    }

    .store-list-wtitle {
        padding: .15rem;
    }

    .store-list-reson {
        font-size: .12rem;
        color: #666;
    }

    .goods-msg {

    }

    .coupons-detail-item {
        font-size: .13rem;
        color: #999999;
        text-align: right;
    }

    .coupons-item {
        border-top: .005rem solid #E5E5E5;
        line-height: .43rem;
    }

    .coupons-detail {
        background-color: #F5F5F5;
        color: #999999;
        padding: 0 .22rem;
        border-radius: .05rem;
        margin-bottom: .18rem;
    }

    .coupons-remark {
        color: #333;
        font-size: .14rem;
        display: inline-block;
        padding-right: .2rem;
    }

    .cart-remark {
        border-top: 1px solid #E5E5E5;
        padding: .18rem 0;
    }

    .text-area {
        width: 100%;
        padding: .02rem;
        color: #333;
        resize: none
    }

    .text-area::-webkit-input-placeholder {
        color: #CCCCCC;
    }

    .text-area::placeholder {
        color: #CCCCCC;
    }

    .cart-count {
        padding: .1rem 0;
        border-top: .005rem solid #E5E5E5;
        color: #000;
    }

    .cart-count-money {
        font-size: .14rem;
    }

    .send-money {
        padding: .05rem 0;
        font-size: .12rem;
        color: #666666;
    }

    .cart-count-wmoney {
        font-weight: bold;
    }

    .change-style {
        top: .01rem;
    }

    .icon-arrows_left {
        transform: rotate(-180deg);
    }

    .cart-no-data {
        position: absolute;
        left: 0;
        top: 0;
        z-index: 1;
    }

    .lose-order {
        border-top: .1rem solid #F5F5F5;
    }

    .total-deposit {
        font-size: .14rem;
        color: #333333;
        display: inline-block;
        padding-right: .3rem;
    }

    .total-deposit-money {
        font-size: .12rem;
        color: #FF3333;
        font-weight: normal;
    }
</style>